package njClass.game
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	
	import njClass.event.PlusEvent;
	
	public class TimeToMove extends EventDispatcher
	{
		//当前移动路线
		private var CurrentWay:Array=new Array();
		//步行计时器
		private var stepTimer:Timer;
		//当前位置
		private var currentPoint:Point;
		
		public function TimeToMove(Speed:int=10)
		{
			stepTimer=new Timer(1000/Speed);
			stepTimer.addEventListener(TimerEvent.TIMER,ToMove);
		}
		
		public function set Way(_way:Array):void{
			CurrentWay=_way;
		}
		
		private function ToMove(evt:TimerEvent):void{
			if(currentPoint==CurrentWay[CurrentWay.length-1]){
				stepTimer.stop();
				this.dispatchEvent(new Event("Moved"));
				return;
			}
			currentPoint=CurrentWay[CurrentWay.indexOf(currentPoint)+1];
			this.dispatchEvent(new PlusEvent("HasMove",currentPoint));
		}
		
		public function Start(startpoint:Point=null):int{
			currentPoint=(startpoint==null?CurrentWay[0]:startpoint);
			stepTimer.start();
			return CurrentWay.length-1;
		}
		
		public function get Steps():int{
			return CurrentWay.length-1;
		}
		
		public function CanMoveSpace(_dis:int):Array{
			var arr:Array=new Array();
			//for(var i:int=0;
			return arr;
		}
		
		public function Stop():void{
			CurrentWay.length=0;
			stepTimer.stop();
		}
		
		public function get CurrentPoint():Point{
			return currentPoint;
		}
	}
}